/*INIT*/
$(document).ready(function() {
	formChecker.init();
});

var formChecker = {
	init: function() {
		$('#form_openRestaurant [name=agree]').click(function(){
			if($(this).hasClass('checked')) $(this).removeClass('checked');
			else $(this).addClass('checked');
		});
		$('#form_openRestaurant .submit').click(formChecker.submit);
	},
	submit: function() {
		var wrong = false;
		$('#form_openRestaurant input:not(.tel,.qq), #form_openRestaurant textarea').each(function(){
			if($(this).val() == '' || $(this).hasClass('inputTips')) {
				alert('请填写完整必填信息！');
				wrong = true;
				return false;
			}
		});
		var form = $('#form_openRestaurant');
		var mobile = form.find('.mobile');
		var tel = form.find('.tel');
		var qq = form.find('.qq');
		
		var reg = /^(1)\d{10}$/;
		if( !mobile.hasClass('inputTips') && !reg.test(mobile.val())) {
			alert('请填写正确的手机号');
			return false;
		}
		reg = /^((029|029-)\d{8}|\d(11)|\d{12})$/;
		if( !tel.hasClass('inputTips') && !reg.test(tel.val())) {
			alert('请填写正确的固定电话');
			return false;
		}

		reg = /^[1-9]\d{4,9}$/;
		if( !qq.hasClass('inputTips') && !reg.test(qq.val())) {
			alert('请填写正确的qq号');
			return false;
		}
		
		if(wrong) return false;
		//if right, set tel and qq to be ""
		if(tel.hasClass('inputTips'))tel.val('');
		if(qq.hasClass('inputTips'))qq.val('');
		
		$('#form_openRestaurant').submit();
	}
};